﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace blackhouse.BlackApart.Data {
    public abstract class AdoApartmentLocationDataAccess : IApartmentLocationDataAccess {

        #region IApartmentLocationDataAccess

        public abstract int Save(int id, double latitude, double longitude, string locationName);

        public ApartmentLocationData Get(int locationId) {
            return this.ReadApartmentLocation(this.GetReaderForApartmentLocation(locationId));
        }

        #endregion

        #region Abstracts

        protected abstract IDataReader GetReaderForApartmentLocation(int locationId);

        #endregion

        #region Methods

        private ApartmentLocationData ReadApartmentLocation(IDataReader reader) {
            if (reader.Read()) {
                ApartmentLocationData data = new ApartmentLocationData();
                data.Id = Convert.ToInt32(reader["Id"]);
                data.Latitude = Convert.ToDouble(reader["Latitude"]);
                data.Longitude = Convert.ToDouble(reader["Longitude"]);
                data.Name = Convert.ToString(reader["Name"]);
				data.CityId = Convert.ToInt32(reader["CityId"]);
				data.City = Convert.ToString(reader["City"]);
				data.DistrictId = Convert.ToInt32(reader["DistrictId"]);
				data.District = Convert.ToString(reader["District"]);
                reader.Close();
                return data;
            } else return default(ApartmentLocationData);
        }


        #endregion

    }
}
